--[[
    SKALOWANIE    
--]]

local sx, sy = guiGetScreenSize() 
local zoom = sx < 1920 and math.min(2, 1920 / sx) or 1

--[[
    KOD    
--]]

function formatNumber(number, sep)
	assert(type(tonumber(number))=="number", "Bad argument @'formatNumber' [Expected number at argument 1 got "..type(number).."]")
	assert(not sep or type(sep)=="string", "Bad argument @'formatNumber' [Expected string at argument 2 got "..type(sep).."]")
	local money = number
	for i = 1, tostring(money):len()/3 do
		money = string.gsub(money, "^(-?%d+)(%d%d%d)", "%1"..sep.."%2")
	end
	return money
end

function removeHex(string)
    if type(string) ~= "string" then return false end
    while(string ~= string.gsub(string, "#%x%x%x%x%x%x", "")) do
        string = string.gsub(string, "#%x%x%x%x%x%x", "")
    end
    return string or false
end

function isMouseInPosition(x, y, width, height)
    if not isCursorShowing() then return false end
	local cx, cy = getCursorPosition()
	local cx, cy = (cx*sx), (cy*sy)
	return ((cx >= x and cx <= x+width) and (cy >= y and cy <= y+height))
end

function getTimeElapsed(last, timeout)
    local timeElapsed = ((last+timeout)-getTickCount())/1000
    return string.format("%.1f", timeElapsed)
end

local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } -- numbers/lowercase chars/uppercase chars

function generateString(len)
    if not tonumber(len) then return false end
    local str = ""
    for i = 1, len do
        local charlist = allowed[math.random(1, 3)]
        str = str..string.char(math.random(charlist[1], charlist[2]))
    end
    return (str or false)
end

function dxDrawLinedRectangle(x, y, w, h, color, width)
    local width = (width or 1)
    dxDrawLine(x, y, x+w, y, color, width, postGUI)
	dxDrawLine(x, y, x, y+h, color, width, postGUI)
	dxDrawLine(x, y+h, x+w, y+h, color, width, postGUI)
	dxDrawLine(x+w, y, x+w, y+h, color, width, postGUI)
end

function dxDrawRoundedRectangle(x, y, width, height, radius, color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+radius, y+radius, width-(radius*2), height-(radius*2), color, postGUI, subPixelPositioning)
    dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI)
    dxDrawCircle(x+radius, (y+height)-radius, radius, 90, 180, color, color, 16, 1, postGUI)
    dxDrawCircle((x+width)-radius, (y+height)-radius, radius, 0, 90, color, color, 16, 1, postGUI)
    dxDrawCircle((x+width)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI)
    dxDrawRectangle(x, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+radius, y+height-radius, width-(radius*2), radius, color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+width-radius, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+radius, y, width-(radius*2), radius, color, postGUI, subPixelPositioning)
end

function hideUI(bool)
    exports['umta_hud']:setHudState(not bool)  
    exports['umta_speedometer']:setSpeedometerState(not bool) 
    exports['umta_radar']:setRadarState(not bool) 
    exports['umta_nametags']:setNametagState(not bool)
    showChat(not bool)
end

function setState(bool)
    hideUI(bool)
end
if exports["umta_csettings"] and exports["umta_csettings"]:settingsGetValue("photoMode") == "1" then setState(true) else setState(false) end

function findPlayer(target)
	local player = false
	local searchType = (tonumber(target) and "id" or "name")
	for i,v in pairs(getElementsByType("player")) do
		if searchType == "id" then
			if getElementData(v, "player:id") == tonumber(target) then
				player = v
				break
			end
		else
			if string.find(string.gsub(string.lower(getPlayerName(v)),"#%x%x%x%x%x%x", ""), string.lower(target), 1, true) then
				player = v
				break
			end
		end
	end
	return player
end
